﻿Public Class frmImportNha
    Dim dt As DataTable = New DataTable()
    Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
        openFile.Filter = "Import du lieu tu file (*.xls)|*.xls | Hoặc file (*.xlsx)|*.xlsx"
        If Not IsNothing(openFile.ShowDialog() = DialogResult.OK) Then
            Try
                Dim path As String = openFile.FileName
                dt = Import.Get_Nha_FromExcel(path)
                gvDSNha.DataSource = dt
            Catch ex As Exception
                MessageBox.Show("Phát hiện lỗi !!\n " + ex.Message, "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End If
      
    End Sub

    Private Sub btnImportNha_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImportNha.Click
        For i As Integer = 0 To dt.Rows.Count - 1
            Dim n As NhaDTO = New NhaDTO()
            Dim macuoi As String = NhaBUS.LayMa_Nha_Cuoi()

            n.strMaNha = NhaBUS.TinhMaNha(macuoi)

            n.strSoNha = dt.Rows(i)(1).ToString()
            n.strDuong = dt.Rows(i)(2).ToString()
            n.iDienTich = dt.Rows(i)(3).ToString()
            n.iGia = dt.Rows(i)(4).ToString()
            n.isTinhTrang = dt.Rows(i)(5).ToString()
            n.iMaLoaiNha = dt.Rows(i)(6).ToString()
            n.iMaQuan = dt.Rows(i)(7).ToString()
            n.isTamXoa = dt.Rows(i)(8).ToString()
            n.strMaNguoiDang = dt.Rows(i)(9).ToString()
            n.strTieuDe = dt.Rows(i)(10).ToString()
            n.dNgayDang = dt.Rows(i)(11).ToString()

            Try
                NhaBUS.Insert(n)
            Catch ex As Exception
                MessageBox.Show("Phát hiện lỗi !!\n " + ex.Message, "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try

        Next

        MessageBox.Show("Nhận dữ liệu thành công !", "THÔNG BÁO")
    End Sub

End Class